package com.AuthServer.config.baseconfig;

import com.AuthServer.job.SecretUpdateJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail secretUpdateJobDetail() {
        return JobBuilder.newJob(SecretUpdateJob.class)
                .withIdentity("SecretUpdateJob")
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger secretUpdateTrigger() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInHours(720)
                .repeatForever();

        return TriggerBuilder.newTrigger()
                .forJob(secretUpdateJobDetail())
                .withIdentity("SecretUpdateTrigger")
                .withSchedule(scheduleBuilder)
                .build();
    }
}

